package com.rathgael.hoteldata.domain;

public class Hotel {

    // IMPORTED FIELDS

    // "LNAME"
    private String name;
    // "ADD1"
    private String address1;
    // "ADD2"
    private String address2;
    // "TOWN"
    private String town;
    // "PC"
    private String postcode;
    // "CTY"
    private String countyCode;
    // "TELE"
    private String telephone;
    // "FAX"
    private String fax;
    // "OWNER"
    private String owner;
    // "BEDS"
    private String beds;
    // "STARS"
    private String stars;
    // "E-MAIL"
    private String email;
    // "WEB"
    private String website;
    // "SALUT"
    private String contactSalutation;
    // "FIRST"
    private String contactFirstNmae;
    // "SURNAME"
    private String contactLSurname;

    public String getFaxMail() {
        String faxNumber = fax;

        // eliminate where there is no fax
        if (faxNumber == null) {
            return null;
        }

        // remove dot separators
        faxNumber = faxNumber.trim().replace(".", "");

        // reject empty numbers
        if (faxNumber.length() < 1) {
            return null;
        }

        // trim leading 0
        if (faxNumber.charAt(0) == '0') {
            faxNumber = faxNumber.substring(1);
        }

        // reject fucked up numbers
        char[] charArray = faxNumber.toCharArray();
        for (char c : charArray) {
            if (!Character.isDigit(c)) {
                return null;
            }
        }

        return "44" + faxNumber + "@efaxsend.com";
    }

    public String getFullContactName() {
        String fullName = "";

        fullName = addNamePart(fullName, contactSalutation);
        fullName = addNamePart(fullName, contactFirstNmae);
        fullName = addNamePart(fullName, contactLSurname);

        return fullName;
    }

    public String getCounty() {
        return County.getByCountyCode(countyCode).getCountyName();
    }

    private String addNamePart(String fullname, String newPart) {
        if (fullname == "") {
            return newPart;
        }
        else {
            return fullname + " " + newPart;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public String getTown() {
        return town;
    }

    public void setTown(String town) {
        this.town = town;
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public String getCountyCode() {
        return countyCode;
    }

    public void setCountyCode(String countyCode) {
        this.countyCode = countyCode;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getBeds() {
        return beds;
    }

    public void setBeds(String beds) {
        this.beds = beds;
    }

    public String getStars() {
        return stars;
    }

    public void setStars(String stars) {
        this.stars = stars;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public String getContactSalutation() {
        return contactSalutation;
    }

    public void setContactSalutation(String contactSalutation) {
        this.contactSalutation = contactSalutation;
    }

    public String getContactFirstNmae() {
        return contactFirstNmae;
    }

    public void setContactFirstNmae(String contactFirstNmae) {
        this.contactFirstNmae = contactFirstNmae;
    }

    public String getContactLSurname() {
        return contactLSurname;
    }

    public void setContactLSurname(String contactLSurname) {
        this.contactLSurname = contactLSurname;
    }
}
